﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Xml;

namespace SmartMD.DataModel.Entity
{
    /** 
 * <p>类说明: 检查项目值</p>
 * @version 1.0
 * <p>文件名： </p>
 * <p>创建人及时间： xiangyuliang 2011-8-27</p>
 * <p>修改人：</p>
 * <p>修改时间：</p>
 * <p>修改描述：</p>
 **/

    public class ExamItemValue : BusinessEntity
    {
        private string _itemId;
        private string _sourceId;

        public override void setValue(string key, Object value)
        {
            if (value is System.DBNull)
                return;
            switch (key.ToLower())
            {
                case "indicevalueid":
                    this.Id = (string)value;
                    break;
                case "sourceid":
                    this.SourceId = (string)value;
                    break;
                case "itemid":
                    this.ItemId = (string)value;
                    break;
                default:
                    ParseValueXml((string)value);
                    break;
            }
        }

        private void ParseValueXml(String xmlData)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlData);
            if (indiceKvps == null)
            {
                indiceKvps = new ObservableCollection<IndiceKVP>();
            }
            IndiceKVP kvp = new IndiceKVP();
            XmlNode root = doc.SelectSingleNode("Document");
            foreach (XmlNode xn in root)
            {
                String nodeName = xn.Name;
                switch (nodeName)
                {
                    case "IndiceName":
                        kvp.Key = xn.InnerText;
                        break;
                    case "Result":
                        kvp.Value = xn.Attributes["Value"].Value.ToString();
                        break;
                    case "Unit":
                        kvp.Unit = xn.InnerText;
                        break;
                    case "ReferenceValue":
                        if (xn.Value != null)
                        {
                            kvp.Reference = (string)(xn.InnerText);
                        }
                        break;
                    default:
                        break;
                }
            }
            indiceKvps.Add(kvp);
        }

        private ObservableCollection<IndiceKVP> indiceKvps;
        public ObservableCollection<IndiceKVP> IndiceKvps
        {
            get
            {
                if (indiceKvps == null)
                {
                    indiceKvps = new ObservableCollection<IndiceKVP>();
                }
                return indiceKvps;
            }
            set
            {
                indiceKvps = value;
                OnPropertyChanged("IndiceKvps");
            }
        }
      
        public String ItemId
        {
            get
            {
                return _itemId;
            }
            set
            {
                _itemId = value;
                OnPropertyChanged(() => ItemId);
            }
        }
        public string SourceId
        {
            get
            {
                return _sourceId;
            }
            set
            {
                _sourceId = value;
                OnPropertyChanged(() => SourceId);
            }
        }
    }
}
